// TypeScript file
class Toast extends egret.DisplayObjectContainer
{
    private static cont : egret.DisplayObjectContainer;
    private static txtrToastBg : egret.Texture;

    public static init(cont : egret.DisplayObjectContainer, txtrToastBg : egret.Texture) : void
    {
        console.log("Toast.init", txtrToastBg);
        this.cont = cont;
        this.txtrToastBg = txtrToastBg;
    }

    public static launch( msg : string )
    {
        if (this.cont)
        {
            var stage = this.cont.stage;
            var toast : Toast = new Toast(msg, stage.stageWidth, stage.stageHeight);
            this.cont.addChild( toast );
        }
    }
    constructor ( msg : string, w : number, h : number )
    {
        super();
        console.log( "Toast:", msg );
        var bg : egret.Bitmap = new egret.Bitmap( Toast.txtrToastBg );
        this.addChild( bg );

        var tx : egret.TextField = new egret.TextField;
        tx.multiline = true;
        tx.size = 20;
        tx.bold = true;
        tx.textColor = 0xFFFFFF;
        tx.stroke = 2;
        tx.strokeColor = 0;
        tx.text = msg;
        tx.fontFamily = "微软雅黑";
        tx.textAlign = egret.HorizontalAlign.CENTER;
        tx.width = w * .84;
        tx.x = ( Toast.txtrToastBg.textureWidth - tx.width ) / 2;
        tx.y = 6;
        this.addChild( tx );

        bg.height = 12 + tx.height;

        this.anchorOffsetX = this.width * .5;
        this.anchorOffsetY = this.height * .5;
        this.x = w * .5;
        this.y = h * .618;
        this.alpha = 0;

        egret.Tween.get( this )
        .to( { alpha : 1 }, 800, egret.Ease.quintOut )
        .wait( 1600 )
        .to( { alpha : 0 }, 1200, egret.Ease.quintIn )
        .call( () =>
         {
            if (this.parent)
            {
                this.parent.removeChild( this );
            }
         }
         );

    }
}